package com.owc.common.tool;

import com.owc.common.enums.ExceptionEnum;
import com.owc.domain.BaseResult;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Jackies
 * @Date 2019/12/1 15:01
 * @Description TODO://
 **/
public class ApiRequestSupport {

    public static void invokeExceptionWrapper(HttpServletResponse response, Integer code, String message)
            throws IOException {
        BaseResult<Object> json = new BaseResult<>();
        json.setCode(code);
        json.setMessage(message);
        json.setData("");
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().write(json.toJson());
    }

    public static void invokeExceptionWrapper(HttpServletResponse response, ExceptionEnum exceptionEnum) throws IOException {
        invokeExceptionWrapper(response,exceptionEnum.getCode(),exceptionEnum.getMessage());
    }

}
